package com.wsm.common.controller;

import com.wsm.common.annotation.DuplicateSubmitToken;
import com.wsm.common.annotation.OperateLog;
import com.wsm.common.business.VisitBusiness;
import com.wsm.common.domain.VisitDO;
import com.wsm.common.utils.PageUtils;
import com.wsm.common.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.Map;
import java.util.concurrent.TimeUnit;

/**
 * 访客记录表
 *
 * @author wangshimin
 * @email wangshiminhome@foxmail.com
 * @date 2020-02-17 12:07:19
 * @description : 访客记录表
 */
@Api(tags = "访客记录表")
@Controller
@RequestMapping("/common/visit")
public class VisitController {
    @Autowired
    private VisitBusiness visitBusiness;

    @GetMapping()
    @ApiOperation(value = "跳转展示界面")
    @RequiresPermissions("common:visit:look")
    String Visit() {
        return "common/visit/visit";
    }

    @ResponseBody
    @GetMapping("/list")
    @ApiOperation(value = "获取集合列表")
    @RequiresPermissions("common:visit:look")
    @DuplicateSubmitToken(save = true, expire = 2, time = TimeUnit.MINUTES)
    public Result<PageUtils> list(@RequestParam Map<String, Object> params) {
        return visitBusiness.list(params);
    }

    @GetMapping("/add")
    @ApiOperation(value = "跳转增加界面")
    @RequiresPermissions("common:visit:add")
    String add() {
        return "common/visit/add";
    }

    @GetMapping("/edit/{id}")
    @ApiOperation(value = "跳转修改界面")
    @RequiresPermissions("common:visit:edit")
    String edit(@PathVariable("id") Long id, Model model) {
        VisitDO visit = visitBusiness.get(id);
        model.addAttribute("visit", visit);
        return "common/visit/edit";
    }

    /**
     * 保存
     */
    @OperateLog("增加访客记录表")
    @ResponseBody
    @PostMapping("/save")
    @ApiOperation(value = "增加")
    @DuplicateSubmitToken(save = true, expire = 2, time = TimeUnit.MINUTES)
    @RequiresPermissions("common:visit:add")
    public Result save(VisitDO visit) {
        return visitBusiness.save(visit);
    }

    /**
     * 修改
     */
    @OperateLog("修改访客记录表")
    @ResponseBody
    @RequestMapping("/update")
    @ApiOperation(value = "修改")
    @DuplicateSubmitToken(save = true, expire = 2, time = TimeUnit.MINUTES)
    @RequiresPermissions("common:visit:edit")
    public Result update(VisitDO visit) {
        return visitBusiness.update(visit);
    }

    /**
     * 删除
     */
    @OperateLog("删除访客记录表")
    @ResponseBody
    @PostMapping("/remove")
    @ApiOperation(value = "删除")
    @DuplicateSubmitToken(save = true, expire = 2, time = TimeUnit.MINUTES)
    @RequiresPermissions("common:visit:remove")
    public Result remove(Long id) {
        return visitBusiness.remove(id);
    }

    /**
     * 删除
     */
    @OperateLog("批量删除访客记录表")
    @ResponseBody
    @PostMapping("/batchRemove")
    @ApiOperation(value = "批量删除")
    @DuplicateSubmitToken(save = true, expire = 2, time = TimeUnit.MINUTES)
    @RequiresPermissions("common:visit:batchRemove")
    public Result remove(@RequestParam("ids[]") Long[] ids) {
        return visitBusiness.batchRemove(ids);
    }


}
